package genedit.controller.interfaceActions;

import genedit.gui.GMainFrame;
import genedit.gui.GProjectTree;
import genedit.model.Package;
import genedit.model.Project;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;

/**
 * Akcija zadužena za kreiranje novog paketa.
 * 
 * @author Nikola
 * @version 1.0 5/11/13
 */
public class GNewPackageA extends AbstractAction {
	private static final long serialVersionUID = 1L;

	protected static GNewPackageA newD = null;

	protected GNewPackageA() {
		putValue(NAME, "New Package");
		putValue(SHORT_DESCRIPTION, "New Package");
		putValue(SMALL_ICON, new ImageIcon("resources/icons/tpackage.png"));
		putValue(MNEMONIC_KEY, KeyEvent.VK_K);
		putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control K"));
	}

	public static AbstractAction getInstance() {
		if (newD == null)
			newD = new GNewPackageA();
		return newD;
	}

	/**
	 * Akcija kreira novi paket unutar izabranog projekta ili paketa i daje mu
	 * podrazumevani naziv.
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		Object p = GProjectTree.getInstance().getTree().getLastSelectedPathComponent();
		if (p instanceof Project) {
			((Project) p).addPackages(new Package((Project) p, GMainFrame.getInstance()
					.getResourceBundle().getString("Package")
					+ " " + ((Project) p).getElementCount()));
		} else if (p instanceof Package) {
			((Package) p).addElements(new Package((Package) p, GMainFrame.getInstance()
					.getResourceBundle().getString("Package")
					+ " " + ((Package) p).getElementCount()));
		} else
			return;
	}

}